<template>
<div>
<center>
  <h3>欢迎来到农产品物流页面</h3>
  <el-table
    :data="tableData"
    style="width: 100%">
    <el-table-column
      prop="id"
      label="运输id">
    </el-table-column>
    <el-table-column
      prop="cropsId"
      label="农作物id">
    </el-table-column>
    <el-table-column
      prop="driverId"
      label="司机账号">
    </el-table-column>
    <el-table-column
      prop="time"
      label="运输时间">
    </el-table-column>
    <el-table-column
      prop="farmerNickName"
      label="农户昵称">
    </el-table-column>
    <el-table-column
      prop="farmerUserName"
      label="农户账号">
    </el-table-column>
    <el-table-column
      prop="farmerTel"
      label="农户手机号">
    </el-table-column>
    <el-table-column
      prop="farmerDept"
      label="农户所在部门">
    </el-table-column>
    <el-table-column
      prop="factoryId"
      label="工厂id">
    </el-table-column>
    <el-table-column
      prop="status"
      label="运输状态">
      <template  slot-scope="scope">
        <span v-if="scope.row.status==0">
          未运输
        </span>
        <span v-if="scope.row.status==1">
          正在运输
        </span>
        <span v-if="scope.row.status==2">
          运输完成
        </span>
      </template>
    </el-table-column>
    <el-table-column
      prop="retailerReceiveStatus"
      label="零售商签收状态">
    </el-table-column>
    <el-table-column
      prop="remarks"
      label="说明">
    </el-table-column>

    <el-table-column
      fixed="right"
      label="操作"
      width="300">
      <template slot-scope="scope">
       <span v-if="scope.row.status==0">
          <el-button @click="stratTrans(scope.row.id)" type="text" size="small">开始配送</el-button>
       </span>

        <span v-if="scope.row.status==1">
          <el-button @click="dingwei(scope.row.id)" type="text" size="small">中途定位</el-button>
          <el-button @click="wanbi(scope.row.id)" type="text" size="small">配送完毕</el-button>
       </span>

      </template>
    </el-table-column>
  </el-table>
</center>

<!--  开始配送对话框-->
  <el-dialog
    title="提示"
    :visible.sync="controlpeisongVisible"
    width="30%">
    <span>是否开始配送货物</span>
    <span slot="footer" class="dialog-footer">
    <el-button @click="controlpeisongVisible = false">取 消</el-button>
    <el-button type="primary" @click=peisong>确 定</el-button>
  </span>
  </el-dialog>


</div>
</template>

<script>
export default {
  name: "index",
  data(){
    return{
      tableData:[],
      controlpeisongVisible:false,
      cid:"",
    }
  },
  methods:{
    //配送完毕
    wanbi(id){
      this.axios.get("http://localhost:2400/wuliu/wanbi?id="+id).then(res=>{
        if(res.data.code==200){
          this.$message.success("货物已配送至目的地");
          this.getlist();
        }else{
          this.$message.error("货物配送失败!");
        }
      })
    },
    //中途定位
    dingwei(id){

    },
    //开始配送
    peisong(){
      this.axios.get("http://localhost:2400/wuliu/updatestatus?id="+this.cid).then(res=>{
        if(res.data.code==200){
          this.$message.success("货物开始配送!");
          this.controlpeisongVisible=false;
          this.getlist();
        }else{
          this.$message.error("货物配送失败!");
        }
      })
    },
    //通知配送
    stratTrans(id){
      this.controlpeisongVisible=true;
      this.cid=id;
    },
    getlist(){
      this.axios.get("http://localhost:2400/wuliu/list").then(res=>{
        this.tableData=res.data.data;
        console.log(this.tableData);
      })
    },
  },
  created() {
    //this.getlist();
  }
}
</script>

<style scoped>

</style>
